import type {
  ApplicationBindMenuParams,
  ApplicationMenuInfo,
  ApplicationQueryBindMenuIdByManyResult,
  ApplicationUpdateBindMenuParams,
  PartPartial,
  RoleBindApplicationParams,
} from '@/types'

const controller = getAjaxBaseUrl('/sysApplicationMenu')

/** 通过应用资源id返回菜单id用于回显 */
export function queryBindMenuId(applicationId: number) {
  return get<number[]>(
    `${controller}/loadMenuIdListByApplication`,
    { applicationId },
  )
}

/** 通过应用资源id或和角色id返回菜单树 */
export function queryBindMenuTree(params: PartPartial<RoleBindApplicationParams, 'roleId'>) {
  return get<Required<ApplicationMenuInfo>[]>(
    `${controller}/loadMenuTreeByApplication`,
    params,
  )
}

/** 通过应用资源id或和角色id返回菜单树 */
export function queryBindMenuIdByMany(params: RoleBindApplicationParams) {
  return get<ApplicationQueryBindMenuIdByManyResult[]>(
    `${controller}/loadMenuIdListByApplicationAndRole`,
    params,
  )
}

/** 菜单绑定应用资源 */
export function batchMenuId(params: ApplicationBindMenuParams[]) {
  return post(`${controller}/batchByApplicationMenu`, params)
}

/** 启用禁用应用资源对应的菜单 */
export function updateBindMenu(params: ApplicationUpdateBindMenuParams) {
  return post(`${controller}/updateApplicationMenu`, params)
}
